﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SuperQuiz.Model;

namespace SuperQuiz.Logic
{
    public static class QuizDataSource
    {
        public async static Task<ObservableCollection<QuizCategory>> GenerateSampleQuizzes()
        {
            return await Task.Run(() =>
                {
                    var quizCategories = new ObservableCollection<QuizCategory>();

                    String ITEM_CONTENT = "Curabitur class aliquam vestibulum nam curae maecenas sed integer cras phasellus suspendisse quisque donec dis praesent accumsan bibendum pellentesque condimentum adipiscing etiam consequat vivamus dictumst aliquam duis convallis scelerisque est parturient ullamcorper aliquet fusce suspendisse nunc hac eleifend amet blandit facilisi condimentum commodo scelerisque faucibus aenean ullamcorper ante mauris dignissim consectetuer nullam lorem vestibulum habitant conubia elementum pellentesque morbi facilisis arcu sollicitudin diam cubilia aptent vestibulum auctor eget dapibus pellentesque inceptos leo egestas interdum nulla consectetuer suspendisse adipiscing pellentesque proin lobortis sollicitudin augue elit mus congue fermentum parturient fringilla euismod feugiat";

                    for (int iCategory = 0; iCategory < 5; iCategory++)
                    {
                        var category = new QuizCategory()
                        {
                            UniqueId = String.Format("C_{0}", iCategory),
                            Name = String.Format("Category {0}", iCategory),
                            ImageUri = "SuperQuiz/Assets/Images/geography.png",
                            Quizzes = new ObservableCollection<Quiz>()
                        };
                        for (int iQuiz = 0; iQuiz < 3; iQuiz++)
                        {
                            var quiz = new Quiz()
                            {
                                UniqueId = String.Format("C_{0}_Q_{1}", iCategory, iQuiz),
                                Name = String.Format("Quiz {0}", iQuiz),
                                Description = ITEM_CONTENT,
                                ImageUri = "SuperQuiz/Assets/Images/geography.png",
                                Questions = new ObservableCollection<QuizQuestion>(),
                                Category = category,
                                AllowPreviousNavigation = true,
                                EvaluateAnswerOnNext = false,
                                LockQuestionWhenEvaluated = true,
                                LockQuestionWhenNavigateToNext = false,
                                LockQuestionWhenNavigateToPrevious = false,
                                AllowShareQuestions = true,
                            };
                            for (int iQuestion = 0; iQuestion < 4; iQuestion++)
                            {
                                var question = new QuizQuestion()
                                {
                                    Code = String.Format("C_{0}_Q_{1}_Q{2}", iCategory, iQuiz, iQuestion),
                                    Title = String.Format("Question {0}", iQuestion),
                                    Description = ITEM_CONTENT,
                                    ImageUri = "SuperQuiz/Assets/Images/geography.png",
                                    Links = new ObservableCollection<QuizUriLink>() 
                                        { 
                                            new QuizUriLink()
                                            {
                                                Url = "http://en.wikipedia.org/wiki/Sao Paulo",
                                                Title = "Wikipedia",
                                            }
                                        },
                                    Answers = new ObservableCollection<QuizAnswer>(),
                                };
                                for (int iAnswer = 0; iAnswer < 4; iAnswer++)
                                {
                                    var answer = new QuizAnswer()
                                    {
                                        Code = String.Format("C_{0}_Q_{1}_Q{2}_A{3}", iCategory, iQuiz, iQuestion, iAnswer),
                                        Name = String.Format("Answer {0}", iAnswer),
                                        Description = ITEM_CONTENT,
                                        ImageUri = "SuperQuiz/Assets/Images/geography.png",
                                        Points = iAnswer - 1,
                                        Links = new ObservableCollection<QuizUriLink>() 
                                        { 
                                            new QuizUriLink()
                                            {
                                                Url = "http://en.wikipedia.org/wiki/Sao Paulo",
                                                Title = "Wikipedia",
                                            }
                                        },
                                    };
                                    question.Answers.Add(answer);
                                }
                                quiz.Questions.Add(question);
                            }
                            category.Quizzes.Add(quiz);
                        }
                        quizCategories.Add(category);
                    }

                    return quizCategories;
                }
            );
        }
    }
}
